<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>微信公众号极速开发</title>
    <link rel="stylesheet" href="static/lib/weui/weui.css"/>
</head>
<body>
<div class="container js_container"></div>
<div class="page">
    <div class="page__hd">
        <h1 class="page__title" style="text-align: center;">极速公众号开发</h1>
    </div>
    <div class="page__bd">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">OpenId</label></div>
                <div class="weui-cell__bd">
                    <%--<input class="weui-input" type="text" name='openId' value="${openId}"/>--%>
                    <input class="weui-input" type="text" name='openId' value="${openId==null?"oRPfZv8WM3ULAx8cSsqyYKRh6T7w":openId}" />
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">金额(￥)</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" name='total_fee' placeholder="请输入金额" value="0.01"/>
                </div>
            </div>
        </div>

        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" href="javascript:" id="btnSubmit">确定</a>
        </div>
    </div>
    <div class="page__ft">
    </div>
</div>
<div class="js_dialog" id="iosDialog2" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd">弹窗内容，告知当前状态、信息和解决方法，描述文字尽量控制在三行内</div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">知道了</a>
        </div>
    </div>
</div>
<script type="text/javascript" src="static/lib/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnSubmit').click(function () {
            var url = '<%=basePath%>jswxpay/unifiedorder', data = {
                'total_fee': $('input[name=total_fee]').val(),
                'openId': $('input[name=openId]').val()
            };

            $.post(url, data, function (res) {
                if (res.status == 0) {
                    alert(res.msg);
                } else if (res.status == 1) {
                    onBridgeReady(res.data);
                }
            });

            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            }
        });

        function onBridgeReady(data) {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', data, function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                    }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                }
            );
        }

    });
</script>
</body>
</html>